package com.gljx.web.service.impl;

import com.gljx.web.Entity.SubjectOneRegentry;
import com.gljx.web.Entity.User;
import com.gljx.web.dao.SubjectOneRegentryMapper;
import com.gljx.web.service.CustomLogService;
import com.gljx.web.service.SubjectOneRegentryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SubjectOneRegentryServiceImpl implements SubjectOneRegentryService {
    @Autowired
    private SubjectOneRegentryMapper subjectOneRegentryMapper;

    @Autowired
    private CustomLogService customLogService;


    @Override
    public int addSubjectOneRegentry(SubjectOneRegentry subjectOneRegentry) {
        // TODO Auto-generated method stub
        return subjectOneRegentryMapper.insertSelective(subjectOneRegentry);
    }

    @Override
    public int deleteByParentId(String parentid, User user,String fbizdate,String fnumber) {
        // TODO Auto-generated method stub
        if(user != null){
            //根据fid查找父类信息
            //根据父类id查找子类信息
            List<SubjectOneRegentry> subjectOneRegentrys = subjectOneRegentryMapper.selSubjectOneRegByParentId(parentid, null);
            for (int i = 0; i < subjectOneRegentrys.size(); i++) {
                //添加学员的服务日志
                customLogService.addLog("考试管理",
                         "删除了学员:"+subjectOneRegentrys.get(i).getCfstudentname()+subjectOneRegentrys.get(i).getStudentName()+",科目一考试登记!申请车型:"+subjectOneRegentrys.get(i).getCfsqzjcxdh()
                                +",考试日期:"+fbizdate+",单据编号:"+fnumber,
                        subjectOneRegentrys.get(i).getCfstudentid(), user.getFid());
            }
        }
        return subjectOneRegentryMapper.deleteByParentId(parentid);
    }

    @Override
    public List<SubjectOneRegentry> selSubjectOneRegByParentId(String fid, String studentName) {
        // TODO Auto-generated method stub
        return subjectOneRegentryMapper.selSubjectOneRegByParentId(fid, studentName);
    }

}
